package cn.tedu.ams.web.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.tedu.ams.dao.UserDao;
import cn.tedu.ams.entity.User;



@WebServlet("/regist.do")
public class RegistServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		UserDao userDao = new UserDao();
		
		User user = new User();
		user.setUsername(request.getParameter("username"));
		user.setPassword(request.getParameter("password"));
		user.setEmail(request.getParameter("email"));
		user.setPhone(request.getParameter("phone"));
		System.out.println("user:"+user);
		boolean flag;
		try {
			flag = userDao.registUser(user);
			if(flag) {
				response.sendRedirect("registSuc.html");
			}else {
				response.sendRedirect("regist.html");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

}
